<!DOCTYPE html>

	<head>
		<% content_for :title, t("title book manager") %>
		<%= stylesheet_link_tag "style" %>
		<script type = "text/javascript">
			function ValidatecheckAll(){
				var giatri = document.getElementById('bookdeleteAll');
				var chk = document.getElementsByName('bookdelete[]');
				if (giatri.checked == true)
				{
					for(i=0; i<chk.length; i++)
					{
						chk[i].checked = true;
					}
				}
				else
				{
					for(i=0; i<chk.length; i++)
					{
						chk[i].checked = false;
					}
				}
			}

			function checkDelete(){
				var del = document.getElementsByName('bookdelete[]');
				var flag = 0;
				for(i=0; i<del.length; i++)
				{
					if (del[i].checked == true)
					flag++;
				}
				if (flag<1)
				{
					alert ("<%= t :alertBook%>");
					return false;
				}
				else {
					return confirm("<%= t :confirm%>"+" "+flag+" "+"<%= t :book%>"+"?");
				}
			}
		</script>
	</head>
	<body id="book-cover">
		<div class="feat_prod_box_details">
			<div class="contact_form1">
				<div class="form_subtitle">
					<%= t :listbook %>
				</div>
				<%if session[:language]== "vi" %>
				<strong class="changepass"><%= link_to t("newbook"), new_book_path+"?lang=vi" %></strong>
				<%else%>
				<strong class="changepass"><%= link_to t("newbook"), new_book_path %></strong>
				<%end%>

				
				
				<%if @books.count > 0%>
				<div id="book_manager">
					<%= form_tag('/book/destroy',:method => :post) do%>
					<table class="table">
						<tr class="book_manager">
							<th class="table">
							<div class="book_manager_title_font">
								<%= t :bookava %>
							</div>
							</th>

							<th class="table">
							<div class="book_manager_title_font">
								<%= t :details %>
							</div>
							</th>
							<th class="table"><%= t :action %></th>
							<th class="table">
							<input id="bookdeleteAll" name="bookdeleteAll" type="checkbox" value="-1" onclick="return ValidatecheckAll()"/>
							</th>
						</tr>

						
							<% @books.each do |book| %>

							<tr>
								<td width="20%" class="table">
									<strong class= "bookimage"><%= image_tag book.image.url(:small) %></strong>
									
								</td>
								<td width="55%" class="table">
								<p>
									<div class="form_row">
										<strong class="book_name"><%= t("title") %></strong>
										<b><span class="book_value"><%= book.title %></span></b>
									</div>
								</p>
								<p>
									<div class="form_row">
										<strong class="book_name"><%= t("author") %></strong>
										<b><span class="book_value"><%= book.author %></span></b>
									</div>
								</p>
								<p>
									<div class="form_row">
										<strong class="book_name"><%= t("version") %></strong>
										<b><span class="book_value"><%= book.version %></span></b>
									</div>
								</p>
								<p>
									<div class="form_row">
										<strong class="book_name"><%= t("publisher") %></strong>
										<b><span class="book_value"><%= book.publisher %></span></b>
									</div>
								</p>
								<p>
									<div class="form_row">
										<strong class="book_name"><%= t("year") %></strong>
										<b><span class="book_value"><%= book.year %></span></b>
									</div>
								</p>
								</td>
								<td width="30%" class="table" class="">
									<%if session[:language]== "vi" %>
										<strong class="changepass"> 
												<%= link_to t("show"), book_path(book)+"?lang=vi" %>
										</strong>
										<br/>
										<strong class="changepass">
											<%= link_to t("edit"), edit_book_path(book)+"?lang=vi" %>
										</strong>
										<br/>
										<strong class="changepass">
											<%= link_to t("destroy"), book, method: :delete, data: { confirm: t("are you sure") } %>
										</strong> 
									<%else%>
										<strong class="changepass">
											<%= link_to t("show"), book %>
										</strong>
										<br/>
										<strong class="changepass">
											<%= link_to t("edit"), edit_book_path(book) %>
										</strong>
										<br/>
										<strong class="changepass">
											<%= link_to t("destroy"), book, method: :delete, data: { confirm: t("are you sure") } %>
										</strong> 
									<%end%> 
								</td>
								<td class="table">
									<%= check_box_tag 'bookdelete[]', book.id %>
								</td>
							</tr>
							<% end %>

					
					</table>
					
						<div class="form_row">
							<input type="submit" class="register" value="<%= t :delete %>" />
						</div>
					<%end%>
					<br />
					<%if session[:language]== "vi" %>
						<strong class="changepass">
							<%= link_to t("newbook"), new_book_path+"?lang=vi" %>
							</strong>
					<%else%>
						<strong class="changepass">
							<%= link_to t("newbook"), new_book_path %>
						</strong>
					<%end%>

				</div>
				<%end%>
				
			</div>
			
		</div>
		
	</body>
